require'coxpcall'
_G.pcall = copcall
copas = require'copas1'
require'ssl'
require'asyncio'
ssl.async(copas)
--ssl.async_handshake=true
--ssl.debug=0
--copas.WATCH_DOG_TIMEOUT=600
--copas.non_block_connect = true
--ssl.async_timeout=0
t={}
completed={}
d=5000
active = 0
failed=0
succeed=0
function f(skt, me)
  active = active + 1
  local a,b,c = ssl.request'https://10.253.253.1:4433'
  if a then print(me, active, #a,b,c)
  else print(me, active, a,b,c) 
  end
  if type(b) == "number" and b < 300 then succeed = succeed + 1 end
  active = active - 1
end

while d > 0 or active > 0 do
  if d > 0 then 
    if active < 800 then
      local co = copas.addthread(f,d) 
      d = d - 1
    end
  end
  if (copas.step(1) == "timeout") then end
end
collectgarbage('collect')
collectgarbage('collect')
print(os.time(),collectgarbage('count'),succeed) 
